//
//  UILabelExt.swift
//  DYSwiftFramework
//
//  Created by huangdeyu on 2021/11/26.
//  Copyright © 2021 none. All rights reserved.
//

import Foundation

// UILabelExtensions.swift - Copyright 2020 SwifterSwift
#if canImport(UIKit) && !os(watchOS)
import UIKit

// MARK: - Methods
public extension UILabel {

    func heightForAttribute(width:CGFloat,lines:Int?) -> CGFloat {
        let label = UILabel(frame: CGRect(x: 0, y: 0, width: width, height: CGFloat.greatestFiniteMagnitude))
        label.numberOfLines = lines ?? numberOfLines
        label.lineBreakMode = lineBreakMode
        label.font = font
        label.attributedText = attributedText
        label.sizeToFit()
        return label.frame.height
    }

}

#endif
